package com.bole.controller;

import com.bole.data.Result;
import com.bole.dto.permission.RoleDto;
import com.bole.feign.RoleFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yakamaxi
 * @version 1.0
 * @date 2020/8/13 8:19
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleFeign roleFeign;

    @GetMapping
    public Result getRole() {
        Result result = roleFeign.get();
        return result;
    }

    @PostMapping
    public Result add(@RequestBody RoleDto role, @RequestParam("rid") Long[] rid) {
        return roleFeign.add(role, rid);
//        return Result.ok();
    }

    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Long id,
                         @RequestBody RoleDto role,
                         @RequestParam("rid") Long[] rid) {
        Result result = roleFeign.updateById(id, role, rid);
        return result;
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id){
        return roleFeign.deleteById(id);
    }

}
